package com.csweimei.rentmanagementtreasure.enterprise.act;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityHouseInfoEntBinding;
import com.csweimei.rentmanagementtreasure.enterprise.viewModel.HouseInfoEntVM;

import me.goldze.mvvmhabit.base.BaseActivity;

public class HouseInfoEntActivity extends BaseActivity<ActivityHouseInfoEntBinding, HouseInfoEntVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_house_info_ent;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    String entID;
    @Override
    public void initParam() {
        super.initParam();
        entID = getIntent().getStringExtra(AppConfig.BUNDLE_KEY);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);
        viewModel.companyid.set(entID);

        binding.tvZz.setOnClickListener(v -> {
            setZz();

        });
        binding.tvHz.setOnClickListener(v -> {
            setHz();
        });

        viewModel.setView(binding.llRoot);

        binding.search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                viewModel.keyword.set(s.toString());
                viewModel.onResume();
            }
        });

    }

    private void setZz() {
        binding.tvZz.setTextSize(18);
        binding.tvZz.setTextColor(getResources().getColor(R.color.text_c));
        binding.tvHz.setTextSize(14);
        binding.tvHz.setTextColor(getResources().getColor(R.color.text_9d));
        viewModel.selType.set("整租");
        viewModel.onResume();

    }

    private void setHz() {
        binding.tvHz.setTextSize(18);
        binding.tvHz.setTextColor(getResources().getColor(R.color.text_c));
        binding.tvZz.setTextSize(14);
        binding.tvZz.setTextColor(getResources().getColor(R.color.text_9d));
        viewModel.selType.set("合租");
        viewModel.onResume();
    }

    @Override
    public HouseInfoEntVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(HouseInfoEntVM.class);
    }
}